package com.flower.service.impl;

import com.flower.mapper.MenuMapper;
import com.flower.model.entity.SysDict;
import com.flower.model.entity.SysMenu;
import com.flower.model.vo.MenuVo;
import com.flower.result.PageResult;
import com.flower.service.MenuService;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@SuppressWarnings("all")
/**
 *@ClassName MenuServiceImpl
 *@Description TODO
 *@Author @O_o  GW__
 *@Date 2025/6/12 10:45
 *@Version 1.0
 */
@Service
@Slf4j
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;

/**
     *@Description 获取所有菜单
     *@Param [name]
     *@return java.util.List<com.flower.model.vo.MenuVo>
     **/
    @Override
    public List<MenuVo> getAllMenu(String name) {
        List<MenuVo> menuVo = menuMapper.getAllMenu(name);
        return menuVo;
    }

    @Override
    public List<SysDict> getIcons() {
        List<SysDict> icons = menuMapper.getIcons();
        return icons;
    }

    @Override
    public void updateMenu(SysMenu sysMenu) {
        if(sysMenu.getId() == null){
            log.info("菜单ID为空,新增菜单");
            menuMapper.addMenu(sysMenu);
            log.info("新增菜单成功");
        }else {
            log.info("菜单ID不为空,修改菜单");
            menuMapper.updateMenu(sysMenu);
            log.info("修改菜单成功");
        }

    }

    @Override
    public void deleteMenu(Integer id) {
        menuMapper.delMenuById(id);
    }

    @Override
    public void deleteMenuList(List<Integer> ids) {
        ids.forEach(id -> menuMapper.delMenuById(id));
    }

    @Override
    public List<Integer> getRoleMenu(Integer roleId) {
        List<Integer> menuIds =  menuMapper.getMenuByIds(roleId);
        return menuIds;
    }
}
